<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	template="../templates/ui.xhtml">

	<ui:define name="content">
	<h1 class="title ui-widget-header ui-corner-all">Collector</h1>
		<div class="entry">
			<p>Collector is an utility component to handle collections in JSF without writing java code.</p>
               
              <h:form id="form">

                <p:growl id="msgs" />

                <p:panel header="Create a new book">
					<h:panelGrid columns="2" id="grid">
						<h:outputLabel value="Title : *" for="txt_title"></h:outputLabel>
						<p:inputText id="txt_title" value="#{createBookBean.book.title}" required="true"/>
						
						<h:outputLabel value="Author : *" for="txt_author"></h:outputLabel>
						<p:inputText id="txt_author" value="#{createBookBean.book.author}" required="true"/>
						
						<p:commandButton value="Reset" type="reset"/>
						<p:commandButton value="Add" update="books msgs @parent" action="#{createBookBean.reinit}" >
							<p:collector value="#{createBookBean.book}" addTo="#{createBookBean.books}" />
						</p:commandButton>
					</h:panelGrid>
				</p:panel>

                <br />
				
				<p:outputPanel id="books">
					<p:dataTable value="#{createBookBean.books}" var="book">

						<p:column>
							<f:facet name="header">
								<h:outputText value="Title" />
							</f:facet>
							<h:outputText value="#{book.title}" />
						</p:column>
	
						<p:column>
							<f:facet name="header">
								<h:outputText value="Author" />
							</f:facet>
							<h:outputText value="#{book.author}" />
						</p:column>
	
						<p:column>
							<f:facet name="header">
								<h:outputText value="Operation" />
							</f:facet>
							<p:commandLink value="Remove" update="form:books" process="@this">
								<p:collector value="#{book}" removeFrom="#{createBookBean.books}" />
							</p:commandLink>
						</p:column>
	
					</p:dataTable>
				</p:outputPanel>

			</h:form>
				
			<h3>Source</h3>
			<p:tabView>
				<p:tab title="collector.xhtml">
					<pre name="code" class="xml">
&lt;h:form id="form"&gt;

    &lt;p:growl id="msgs" /&gt;

	&lt;p:panel header="Create a new book"&gt;
		&lt;h:panelGrid columns="2" id="grid"&gt;
			&lt;h:outputLabel value="Title : *" for="txt_title"&gt;&lt;/h:outputLabel&gt;
			&lt;p:inputText id="txt_title" 
							value="\#{createBookBean.book.title}" required="true"/&gt;
			
			&lt;h:outputLabel value="Author : *" for="txt_author"&gt;&lt;/h:outputLabel&gt;
			&lt;p:inputText id="txt_author" required="true" 
							value="\#{createBookBean.book.author}" /&gt;
			
			&lt;p:commandButton value="Reset" type="reset"/&gt;
			&lt;p:commandButton value="Add" update="books msgs @parent"
							action="\#{createBookBean.reinit}" &gt;
				&lt;p:collector value="\#{createBookBean.book}" 
							addTo="\#{createBookBean.books}" /&gt;
			&lt;/p:commandButton&gt;
		&lt;/h:panelGrid&gt;
	&lt;/p:panel&gt;
	
	&lt;p:outputPanel id="books"&gt;
		&lt;p:dataTable value="\#{createBookBean.books}" var="book"&gt;

			&lt;p:column&gt;
				&lt;f:facet name="header"&gt;
					&lt;h:outputText value="Title" /&gt;
				&lt;/f:facet&gt;
				&lt;h:outputText value="\#{book.title}" /&gt;
			&lt;/p:column&gt;

			&lt;p:column&gt;
				&lt;f:facet name="header"&gt;
					&lt;h:outputText value="Author" /&gt;
				&lt;/f:facet&gt;
				&lt;h:outputText value="\#{book.author}" /&gt;
			&lt;/p:column&gt;

			&lt;p:column&gt;
				&lt;f:facet name="header"&gt;
					&lt;h:outputText value="Operation" /&gt;
				&lt;/f:facet&gt;
				&lt;p:commandLink value="Remove" update="form:books" process="@this"&gt;
					&lt;p:collector value="\#{book}"
								 removeFrom="\#{createBookBean.books}" /&gt;
				&lt;/p:commandLink&gt;
			&lt;/p:column&gt;

		&lt;/p:dataTable&gt;
	&lt;/p:outputPanel&gt;

&lt;/h:form&gt;
					</pre>
				</p:tab>
				
				<p:tab title="CreateBookBean.java">
					<pre name="code" class="java">
public class CreateBookBean {

	private Book book = new Book();
	
	private List&lt;Book&gt; books = new ArrayList&lt;Book&gt;();

	public String reinit() {
		book = new Book();
		
		return null;
	}

	public Book getBook() {
		return book;
	}

	public void setBook(Book book) {
		this.book = book;
	}

	public List&lt;Book&gt; getBooks() {
		return books;
	}

	public void setBooks(List&lt;Book&gt; books) {
		this.books = books;
	}
}	
					</pre>
				</p:tab>
			</p:tabView>

   		</div>
     

	</ui:define>
</ui:composition>